package com.firebird.app.kotlin.stock.utils

import android.content.Context
import android.graphics.Color
//import android.text.format.DateUtils
import android.widget.TextView
import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnOptionsSelectListener
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.bigkoo.pickerview.view.OptionsPickerView
import com.bigkoo.pickerview.view.TimePickerView
import com.firebird.app.kotlin.stock.R

object SelectorUtils {
    var pvCustomTime: TimePickerView? = null
    fun initCustomTimePickerStart(context: Context?, textView: TextView, dateType: String?) { //时间选择器 ，自定义布局
        pvCustomTime = TimePickerBuilder(context, OnTimeSelectListener { date, v ->
            //选中事件回调
            textView.setText(DateUtils.getHM(date, dateType))
        })
                .setLayoutRes(R.layout.pickerview_custom_time) { v ->
                    val tvSubmit = v.findViewById<TextView>(R.id.tv_finish)
                    val ivCancel = v.findViewById<TextView>(R.id.tv_cancle)
                    tvSubmit.setOnClickListener {
                        pvCustomTime!!.returnData()
                        pvCustomTime!!.dismiss()
                    }
                    ivCancel.setOnClickListener { pvCustomTime!!.dismiss() }
                }
                .setContentTextSize(18)
                .setType(booleanArrayOf(true, true, true, false, false, false))
                .setLabel("年", "月", "日", "时", "分", "秒")
                .setLineSpacingMultiplier(1.2f)
                .setTextXOffset(0, 0, 0, 40, 0, -40)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(Color.parseColor("#999999"))
                .build()
        pvCustomTime.show()
    }

    fun chooseType(context: Context?, textView: TextView, list: List<String?>) {
        val pvNoLinkOptions: OptionsPickerView<*> = OptionsPickerBuilder(context, OnOptionsSelectListener { options1, options2, options3, v -> textView.text = list[options1] }).setCancelColor(Color.parseColor("#999999"))
                .setSubmitColor(Color.parseColor("#ff3025"))
                .setTitleBgColor(Color.parseColor("#ffffff"))
                .setContentTextSize(14)
                .setSubCalSize(14)
                .setContentTextSize(18)
                .build<Any>()
        pvNoLinkOptions.setNPicker(list, null, null)
        pvNoLinkOptions.show()
    }
}